<?php

/**

 * Created by PhpStorm.

 * User: 悟能科技

 * Date: 2018/7/31

 * Time: 9:15

 */



namespace app\admin\controller;





use think\Controller;



class Uploads extends Controller

{

//编辑器上传

    public function uploade(){

        $file = request()->file('file');

//        return json($file);

        if ($file) {

            $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads/conten');

            if ($info) {

                $imgurl = '/uploads/conten/' . $info->getSaveName();

                $data['errno'] = '0';

                $data['data'] = [$imgurl];

                $data['message'] = 'SUCCESS';

            } else {

                $data['code'] = '9002';

                $data['data'] = '';

                $data['message'] = 'ERROR';

            }

        }else{

            $data['code'] = '9001';

            $data['data'] = '';

            $data['message'] = 'ERROR';

        }

        return json($data);



    }

    //缩略图上传

    public function uploadt(){
        $file = request()->file('file');
        if ($file) {
            $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads/thumb');
            if ($info) {
                $imgurl = '/uploads/thumb/' . $info->getSaveName();
                $data['code'] = '9002';
                $data['data'] = $imgurl;
                $data['message'] = 'ERROR';
            } else {
                $data['code'] = '9002';
                $data['data'] = '';
                $data['message'] = 'ERROR';
            }
        }else{
            $data['code'] = '9001';
            $data['data'] = '';
            $data['message'] = 'ERROR';
        }
        return json($data);
    }



    //缩略图上传

    public function uploadi(){
        $file = request()->file('file');
        if ($file) {
            $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads/index');
            if ($info) {
                $imgurl = request()->domain().'/uploads/index/' . $info->getSaveName();
                $data['code'] = '0';
                $data['data'] = $imgurl;
                $data['message'] = 'SUCCESS';
            } else {
                $data['code'] = '9002';
                $data['data'] = '';
                $data['message'] = 'ERROR';
            }
        }else{
            $data['code'] = '9001';
            $data['data'] = '';
            $data['message'] = 'ERROR';
        }
        return json($data);
    }


    public function uploads(){
        $file = request()->file('file');
        if ($file) {
            $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads/set');
            if ($info) {
                $imgurl = request()->domain().'/uploads/set/' . $info->getSaveName();
                $data['code'] = '0';
                $data['data'] = $imgurl;
                $data['message'] = 'SUCCESS';
            } else {
                $data['code'] = '9002';
                $data['data'] = '';
                $data['message'] = 'ERROR';
            }
        }else{
            $data['code'] = '9001';
            $data['data'] = '';
            $data['message'] = 'ERROR';
        }
        return json($data);
    }

    public function uploadzs(){
        $file = request()->file('file');
        if ($file) {
            $info = $file->move(EXTEND_PATH . 'Weixinpay' . DS . 'cert');
            if ($info) {
                $pem['url'] = EXTEND_PATH . 'Weixinpay/cert/'.$info->getSaveName();
                $pem['ext'] = $info->getExtension();
                $data['url'] = $pem['url'];
                $data['code'] = 0;
            } else {
                $data['code'] = '9002';
                $data['data'] = '';
                $data['message'] = 'ERROR';
            }
        }else{
            $data['code'] = '9001';
            $data['data'] = '';
            $data['message'] = 'ERROR';
        }
        return json($data);
    }

    public function uploadmusic(){
        $file = request()->file('file');
        if ($file) {
            $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads/video');
            if ($info) {
                $imgurl = request()->domain().'/uploads/video/' . $info->getSaveName();
                $data['code'] = '0';
                $data['data'] = $imgurl;
                $data['message'] = 'SUCCESS';
            } else {
                $data['code'] = '9002';
                $data['data'] = '';
                $data['message'] = 'ERROR';
            }
        }else{
            $data['code'] = '9001';
            $data['data'] = '';
            $data['message'] = 'ERROR';
        }
        return json($data);
    }



    //缩略图上传

    public function uploadb(){

        $file = request()->file('file');

        if ($file) {

            $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads/banner');

            if ($info) {

                $imgurl = request()->domain().'/uploads/banner/' . $info->getSaveName();

                $data['code'] = '0';

                $data['data'] = $imgurl;

                $data['message'] = 'SUCCESS';

            } else {

                $data['code'] = '9002';

                $data['data'] = '';

                $data['message'] = 'ERROR';

            }

        }else{

            $data['code'] = '9001';

            $data['data'] = '';

            $data['message'] = 'ERROR';

        }

        return json($data);



    }
//上传证书
    public function uploadpem(){
        $file = request()->file('file');
        $info = $file->move(EXTEND_PATH . 'Weixinpay/cert/');

        if($info){
            $pem['url'] = EXTEND_PATH . 'Weixinpay/cert/'.$info->getSaveName();
            $pem['ext'] = $info->getExtension();
            $data['url'] = $pem['url'];
            $data['code'] = 0;
            return json($data);
        }else{
            return json($file->getError());
        }
    }


}